package cn.kgc.flightdemo01.controller;

import cn.kgc.flightdemo01.pojo.City;
import cn.kgc.flightdemo01.pojo.Flight;
import cn.kgc.flightdemo01.pojo.ResultEntity;
import cn.kgc.flightdemo01.pojo.ViewsFlightCity;
import cn.kgc.flightdemo01.service.FlightService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin(origins = "http://localhost:8081")
@RestController
public class FlightController {

    @Resource
    FlightService flightService;

    @RequestMapping("/selectFlight")
    public Map<String,Object> selectFlight(@RequestParam(value = "departurecity",defaultValue = "0")Integer departurecity,
                                           @RequestParam(value = "arrivalcity",defaultValue = "0") Integer arrivalcity){
        Map<String,Object> map=new HashMap<>();
        map.put("fight",flightService.selectAllFlight(departurecity,arrivalcity));
        return map;
    }

    @RequestMapping("/selectCity")
    public  ResultEntity<List<City>> selectCity(){
        List<City> cityList = flightService.selectAll();
        return ResultEntity.successWithoutData(cityList);
    }


    @RequestMapping("/saveFlight")
    public  ResultEntity<Integer> saveFlight(@RequestBody Flight flight){
        return ResultEntity.successWithoutData(flightService.SaveFlight(flight));
    }


}
